package com.island.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;


public class PageUtil {

    private static PageSupport pageSupport= new PageSupport();

    public static PageSupport getPageSupport(String pageIndex,int totalCount){

        int pageSize = 8; //设置每页的最大数据条数
        int currentPageNo = 1;

        if (pageIndex!=null){
            currentPageNo = Integer.parseInt(pageIndex);//设置当前页数
        }

        pageSupport.setUrl("userManager");
        pageSupport.setPageSize(pageSize);//设置一页多少行数据
        pageSupport.setTotalCount(totalCount);//设置总数量
        pageSupport.setCurrentPageNo(currentPageNo);//设置当前页数
        int totalPageCount = 0;
        totalPageCount = pageSupport.getTotalPageCount(); //获取总页数

        //4、控制翻页
        if (currentPageNo<1){//在第一页的时候还想点击上一页
            currentPageNo = 1;
        }else if(currentPageNo>pageSupport.getTotalPageCount()) {//在第最后一页的时候还想点击下一页
            currentPageNo = totalPageCount;
        }
        return pageSupport;
    }
}
